#include "Movie.h"
#include <iostream>
#include <string>

using namespace std;

Movie::Movie(void) : size(0), head(NULL), rentedCount(0), left(NULL), right(NULL) {

}

Movie::~Movie(void) {

}

int Movie::dvdCount() {
	return size; // returns number of DVDs
}

void Movie::addDvd(Dvd* newItem) {
	// add a new DVD to a movie
	Dvd *newDvd = new Dvd;

	newDvd = newItem;
	newDvd->next = head;
	head = newDvd;
	size++;
}

Dvd *Movie::retrieveDvd(int position) {
	// gets the DVD position of a movie
	Dvd *currentPosition = head;

	for(int i = 0; i < position && currentPosition != NULL; i++) {
		// traverses till we find the current position
		currentPosition = currentPosition->next;
	}
	return currentPosition;
}

bool Movie::deleteDvd(int position) {
	// deletes the DVD from the Movie object
	if (retrieveDvd(position) == NULL) {
		return false;
	} else {
		// node exsists
		// if previous node doesn't exsist then we are at the start
		if (retrieveDvd(position-1) == NULL) {
			// fix the beginning pointer to the current next pointer
			head->next = retrieveDvd(position+1);
		} else {
			// fix the previous pointer to the next next pointer
			retrieveDvd(position-1)->next = retrieveDvd(position+1);
		}

		size--;
		return true;
	}
}

void Movie::setLeft(Movie* newLeft) {
	left = newLeft; // sets left child
}

Movie* Movie::getLeft() {
	return left; // gets left child
}

void Movie::setRight(Movie* newRight) {
	right = newRight; // sets right child
}

Movie* Movie::getRight() {
	return right; // gets right child
}

/*
/ Set methods: sets a movie's detail
/ Get methods: return a movie's detail 
*/
void Movie::setTitle(std::string newTitle) {
	title = newTitle;
}

string Movie::getTitle() {
	return title; 
}

void Movie::setStarring(std::string newStarring) {
	starring = newStarring;
}

string Movie::getStarring() {
	return starring;
}

void Movie::setDirector(std::string newDirector) {
	director = newDirector;
}

string Movie::getDirector() {
	return director;
}

void Movie::setDuration(std::string newDuration) {
	duration = newDuration;
}

string Movie::getDuration() {
	return duration;
}

void Movie::setGenre(std::string newGenre) {
	genre = newGenre;
}

string Movie::getGenre() {
	return genre;
}

void Movie::setClassification(std::string newClassification) {
	classification = newClassification;
}

string Movie::getClassification() {
	return classification;
}

void Movie::setReleaseDate(std::string newReleaseDate) {
	release_date = newReleaseDate;
}

string Movie::getReleaseDate() {
	return release_date;
}

void Movie::setMovieId(int newMovieId) {
	movieId = newMovieId; // sets movie's identification
}

int Movie::getMovieId() {
	return movieId; // returns the movie's identification
}

std::string Movie::getMovieBinaryId() {
	// searches and returns a movie's identification
	string movieBinaryId = "";
	movieBinaryId += title;
	movieBinaryId += movieId;
	return movieBinaryId;
}

void Movie::incrementRentalCount() {
	rentedCount++;
}

int Movie::getRentalCount() {
	return rentedCount;
}